package com.probox.modules.controller.customer;

import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.entity.domain.customer.RechargeInfoRights;
import com.probox.common.entity.service.customer.IRechargeInfoRightsService;
import com.probox.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 充值对应的权益Controller
 *
 * @author usoft
 * @date 2022-09-14
 */
@RestController
@RequestMapping("/system/rights")
public class RechargeInfoRightsController extends BaseController
{
    @Autowired
    private IRechargeInfoRightsService rechargeInfoRightsService;

/**
 * 查询充值对应的权益列表
 */
@GetMapping("/list")
    public TableDataInfo list(RechargeInfoRights rechargeInfoRights)
    {
        startPage();
        List<RechargeInfoRights> list = rechargeInfoRightsService.queryList(rechargeInfoRights);
        return getDataTable(list);
    }

    /**
     * 导出充值对应的权益列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, RechargeInfoRights rechargeInfoRights) throws IOException
    {
        List<RechargeInfoRights> list = rechargeInfoRightsService.queryList(rechargeInfoRights);
        ExcelUtil<RechargeInfoRights> util = new ExcelUtil<RechargeInfoRights>(RechargeInfoRights.class);
        util.exportExcel(response, list, "充值对应的权益数据");
    }

    /**
     * 获取充值对应的权益详细信息
     */
    @GetMapping(value = "/{rightId}")
    public AjaxResult getInfo(@PathVariable("rightId") Long rightId)
    {
        return AjaxResult.success(rechargeInfoRightsService.selectRechargeInfoRightsById(rightId));
    }

    /**
     * 新增充值对应的权益
     */
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody RechargeInfoRights rechargeInfoRights)
    {
        return toAjax(rechargeInfoRightsService.insertRechargeInfoRights(rechargeInfoRights));
    }

    /**
     * 修改充值对应的权益
     */
    @PreAuthorize(hasPermi ="system:rights:edit")
    @PutMapping(value = "/edit")
    public AjaxResult edit(@RequestBody RechargeInfoRights rechargeInfoRights)
    {
        return toAjax(rechargeInfoRightsService.updateRechargeInfoRights(rechargeInfoRights));
    }

    /**
     * 删除充值对应的权益
     */
    @DeleteMapping("/{rightIds}")
    public AjaxResult remove(@PathVariable Long[] rightIds)
    {
        return toAjax(rechargeInfoRightsService.deleteRechargeInfoRightsByIds(rightIds));
    }
}
